package parser;

import antlr.RecognitionException;
import antlr.Token;
import java.util.*;

class ListExpr extends Expr {
    
    List<Expr> members;
    
    ListExpr(List<Expr> members) {
        this.members = members;
    }
    
    void lhs() throws RecognitionException {
        for (Expr e : members)
            e.lhs();
    }

    void delete(ByteStream out) throws RecognitionException {
        throw new RecognitionException("Cannot delete rvalue");
    }

    void write(ByteStream out) throws RecognitionException {
        // This is wrong - It could overflow the stack...
        
        for (Expr e : members) {
            e.write(out);
        }
        out.write(Opcodes.LIST);
        out.write(members.size());
        
        // Creat new emptylist:
        // for (Expr e : members) {
        //    e.write(out);
        //   add e to list
        //}
    }
    
    void writeLHS(ByteStream out) throws RecognitionException {
        // This is the same as tuple assignment.
        Tuple.unpack(members, out);
    }
  
}
